//////////////////////////////////////////////////////////////////////////
//
// Vector Graph Core2D
//
// Module:
//        Mirror2D.cs
//
// Description:
//        Implementation of mirror reflection operation
//
// Author:
//        Created on 2008.04.17 by Destrayer
//
//////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;

namespace VectorGraph.Core2D
{
    class Mirror2D
    {
        public static void Mirror(ref Point2d pt, Beeline2d baseLine)
        {
            Point2d closestPt = ClosestPoint2D.ClosestPoint(baseLine, pt);
            pt -= closestPt;
            pt.Inverse();
            pt += closestPt;
        }

        public static void Mirror(ref Beeline2d bl, Beeline2d baseLine)
        {
            Mirror2D.Mirror(ref bl.BasePt, baseLine);
            Mirror2D.Mirror(ref bl.Direction, baseLine);
        }

        public static void Mirror(ref Circle2d c, Beeline2d baseLine)
        {
            Mirror2D.Mirror(ref c.CenterPt, baseLine);
        }

        public static void Mirror(ref Segment2d seg, Beeline2d baseLine)
        {
            Mirror2D.Mirror(ref seg.StartPt, baseLine);
            Mirror2D.Mirror(ref seg.EndPt, baseLine);
        }

        public static void Mirror(ref Arc2d arc, Beeline2d baseLine)
        {
            Mirror2D.Mirror(ref arc.CenterPt, baseLine);
            Mirror2D.Mirror(ref arc.StartVector, baseLine);
            Mirror2D.Mirror(ref arc.EndVector, baseLine);
        }

        public static void Mirror(ref Path2d path, Beeline2d baseLine)
        {
            for (int i = path.Count - 1; i >= 0; i--)
            {
                Point2d pt = path.Vertex(i);
                Mirror2D.Mirror(ref pt, baseLine);
                path.SetVertex(i, pt);
            }
        }

        public static void Mirror(ref Polygon2d poly, Beeline2d baseLine)
        {
            for (int i = poly.Count - 1; i >= 0; i--)
            {
                Point2d pt = poly.Vertex(i);
                Mirror2D.Mirror(ref pt, baseLine);
                poly.SetVertex(i, pt);
            }
        }
    }
}
